<html>
<head>
	<title>GobbleRSS</title>
	<link href="css/gob.css" type="text/css" rel="stylesheet">
	<script type="text/javascript" src="js/prototype.js"></script>
	<script type="text/javascript" src="js/sexybox.js"></script>
	<script type="text/javascript" src="js/gob.js"></script>
</head>

<body>
<div id="sexyBG"></div><div id="sexyBOX"></div>

<div style="padding-top: 10px; float: right">
	<?php include ('menu.inc.php') ?>
</div>

<h1>Articles Filters</h1>

<?php
include('functions.inc.php');
$link = db_connect();

if (isset($_POST['save_filters'])) {
	foreach ($_POST as $key => $value) {
		if (empty($value)) {
			continue;
		}
		if (strstr($key, 'filter_') === false) {
			continue;
		}
		$id = str_replace("filter_", '', $key);
		$query = sprintf("INSERT INTO filters (id,value) VALUES ($id, '%s') ON DUPLICATE KEY UPDATE value=VALUES(value)", mysql_escape_string($value));
		mysql_query($query)
			or die("Could not save new filters.");
	}
	mysql_query("DELETE FROM filters WHERE value IS NULL or value = ''");
	?>
	<span class="success">
		New filters successfully saved.
	</span><br/>
	<?php
}

$query = "SELECT id, value FROM filters ORDER BY id";
$result = mysql_query($query)
	or die("Could not fetch filters.");
$filters = array();
while ($filter = mysql_fetch_object($result)) {
	$filters[$filter->id] = $filter->value;
}
$id = 0;
header("Content-type: text/html; charset=UTF-8");
?>

<div>
	Specify substrings that, if found in articles (title or content), will hide them from your reading list.<br/>
	<form method="POST" action="filters.php">
		<?php foreach ($filters as $id => $filter) : ?>
			<input type="text" name="filter_<?php print htmlentities($id) ?>" value="<?php print htmlentities($filter) ?>" /><br/>
		<?php endforeach; ?>
		<input type="text" name="filter_<?php print ($id+1) ?>" value="" /><br/>
		<input type="submit" name="save_filters" value="Save" />
	</form>
</div>

</body>
</html>
